from tortoise import fields
from tortoise.models import Model


class TimestampMixin(Model):
    create_time = fields.DatetimeField(auto_now_add=True, description='创建时间')
    update_time = fields.DatetimeField(auto_now=True, description="更新时间")
    version = fields.IntField(default=0)

    class Meta:
        abstract = True

class OperateLog(TimestampMixin):
    user_id = fields.IntField(description="用户ID")
    target_url = fields.CharField(null=True, description="访问的url", max_length=255)
    user_agent = fields.CharField(null=True, description="访问UA", max_length=255)
    request_params = fields.JSONField(null=True, description="请求参数get|post")
    ip = fields.CharField(null=True, max_length=32, description="访问IP")
    note = fields.CharField(null=True, max_length=255, description="备注")
    sql = fields.TextField(null=True,  description="SQL语句")

    class Meta:
        table_description = "用户操作记录表"
        table = "operate_log"
        
class Fortest(TimestampMixin):
    test_1 = fields.IntField(null=True)
    test_2 = fields.CharField(256, null=True)
    test_3 = fields.CharField(256, null=True)
    test_4 = fields.CharField(256, null=True)
    test_5 = fields.CharField(256, null=True)
    test_6 = fields.CharField(256, null=True)

    class Meta:
        table_description = "for test"
        table = "for_test"